﻿using EntityStore;
using EntityStore.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace WinformBlazor.Components
{
    public class Page
    {
        public ControlInfo MainPage { get; set; } = new()
        {
            Name = "主页面",
            Id = "main",
            Type = ContrloType.Form,
            Style = new Style()
            {
                height = "100%",
                width = "100%",
                position = Position.relative,
            },
            Class = new Class() { Gutter = 0 }
        };




        /// <summary>s
        /// 更新页面的委托
        /// </summary>
        [JsonIgnore] public Action? UpdateHander { get; set; }
        /// <summary>
        /// 设计器中被选中的控件
        /// </summary>
        [JsonIgnore] public ControlInfo? SelectControl { get; set; }

        [JsonIgnore] public ContrloType? SelectedBox { get; set; }
        [JsonIgnore] public double SelectedBoxOffx { get; set; }
        [JsonIgnore] public double SelectedBoxOffy { get; set; }
        public int Index { get; set; }


    }
    /// <summary>
    /// 表示一个控件
    /// </summary>
    public class ControlInfo
    {
        public string Id { get; set; } = Guid.NewGuid().ToString();
        public string Name { get; set; } = Guid.NewGuid().ToString();
        public ContrloType Type { get; set; }
        /// <summary>
        /// 父级
        /// </summary>
        public ControlInfo? ParentControl { get; set; }
        /// <summary>
        /// 他的子组件
        /// </summary>
        public List<ControlInfo> Childs { get; set; } = new();

        /// <summary>
        /// 控件的外观,风格在这里设置
        /// </summary>
        public Style Style { get; set; } = new();

        public Class Class { get; set; } = new();
        /// <summary>
        /// 包装这个控件的容器所占用如容器的宽度
        /// </summary>
        public int WrapperWidth { get; set; } = 1;
       
        /// <summary>
        /// 控件是否为容器控件
        /// </summary>
        public bool IsContainer
        {
            get
            {
                switch (Type)
                {
                    case ContrloType.Form:
                    case ContrloType.Panel:
                        return true;
                    case ContrloType.Textbox:
                        break;
                    case ContrloType.Button:
                        break;
                    case ContrloType.Label:
                        break;
                    case ContrloType.CheckBox:
                        break;
                    default:
                        break;
                }
                return false;

            }
            set
            {

            }
        }

        public void Save()
        {
            ///在保存的时候,将Style和Class直接转化成字符串,然后实际页面的时候,用转化后的,这样优化性能,保存的时候都保存,但是在实际展示页面的时候,我们查询只需要查询字符串形式的就好了
        }
    }
    public enum ContrloType
    {
        Form,
        Textbox,
        Button,
        Panel,
        Label,
        CheckBox
    }
    /// <summary>
    /// 定位方式
    /// </summary>
    public enum PositionCss
    {

    }
}
